﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.PerContainerLifetime
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Diagnostics.CodeAnalysis;

#nullable disable
namespace MCM.LightInject
{
  [LifeSpan(30)]
  [ExcludeFromCodeCoverage]
  internal class PerContainerLifetime : ILifetime, ICloneableLifeTime
  {
    private readonly object syncRoot = new object();
    private volatile object singleton;

    public object GetInstance(Func<object> createInstance, Scope scope)
    {
      throw new NotImplementedException("Optimized");
    }

    public object GetInstance(GetInstanceDelegate createInstance, Scope scope, object[] arguments)
    {
      if (this.singleton != null)
        return this.singleton;
      lock (this.syncRoot)
      {
        if (this.singleton == null)
          this.singleton = createInstance(arguments, scope);
      }
      return this.singleton;
    }

    public ILifetime Clone() => (ILifetime) new PerContainerLifetime();
  }
}
